package cn.mahjong.controller;

import cn.hserver.plugin.web.annotation.WebSocket;
import cn.hserver.plugin.web.context.WebConstConfig;
import cn.hserver.plugin.web.handlers.Ws;
import cn.hserver.plugin.web.interfaces.WebSocketHandler;
import cn.hutool.json.JSONUtil;
import cn.mahjong.bean.MahJongBean;
import cn.mahjong.bean.MahJongUserBean;
import cn.mahjong.bean.PlayMsg;
import cn.mahjong.service.MahJongService;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.util.List;

@WebSocket("/ws")
public class WsController implements WebSocketHandler {

    public static MahJongService mahJongService = new MahJongService();

    @Override
    public void onConnect(Ws ws) {

    }

    @Override
    public void onMessage(Ws ws) {
        PlayMsg playMsg = JSONUtil.toBean(ws.getMessage(), PlayMsg.class);
        if (playMsg == null) {
            return;
        }
        switch (playMsg.getType()) {
            //连接
            case CONNECT -> {
                mahJongService.addUser(ws, playMsg.getUserId());
            }
            //用户出牌，出牌用户，少于13张就给他莫一张牌
            case PLAY_CARDS -> {

            }
        }
        mahJongService.handlerEvent();
    }

    @Override
    public void disConnect(Ws ws) {

    }
}
